package cxt.com.recyclerview.demo1;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import java.util.ArrayList;

import cxt.com.recyclerview.R;

/**
 * 作者：chengxiangtong on 2017/1/9 14:01
 * 邮箱：528440900@qq.com
 */

public class NormalAdapter extends RecyclerView.Adapter<NormalAdapter.ViewHolders> {

    private Context mContext;
    private ArrayList<DataModel> dataModels = new ArrayList<>();

    public NormalAdapter(Context mContext, ArrayList<DataModel> dataModels) {
        this.mContext = mContext;
        this.dataModels = dataModels;
    }

    @Override
    public ViewHolders onCreateViewHolder(ViewGroup parent, int viewType) {
        View mView = LayoutInflater.from(mContext).inflate(R.layout.item_1, parent, false);
        return new ViewHolders(mView);
    }

    @Override
    public void onBindViewHolder(ViewHolders holder, int position) {
        holder.title.setText(dataModels.get(position).getTitle());
        holder.number.setText(dataModels.get(position).getNumber() + "");
    }


    @Override
    public int getItemCount() {
        return dataModels.size();
    }


    class ViewHolders extends RecyclerView.ViewHolder {
        private TextView title;
        private TextView number;

        ViewHolders(View itemView) {
            super(itemView);
            title = (TextView) itemView.findViewById(R.id.title);
            number = (TextView) itemView.findViewById(R.id.number);

        }
    }
}
